package bma.common.netty.webserver;

import java.util.UUID;

import org.junit.Before;
import org.junit.Test;

import bma.common.langutil.core.ObjectUtil;
import bma.common.langutil.io.IOUtil;
import bma.common.langutil.log.LogbackUtil;
import bma.common.netty.webserver.NettyWebServer;
import bma.common.netty.webserver.file.RequestProcessorStaticFile;

public class NettyWebServerTC {

	@Before
	public void setUp() {
		LogbackUtil.setLevel("bma.common.langutil.concurrent.ProcessTimeWheel",
				"INFO");
	}

	public NettyWebServer server() {
		NettyWebServer s = new NettyWebServer();
		s.setPort(1080);
		s.setName("webServer");
		s.setTraceBufferSize(1024);
		return s;
	}

	@Test
	public void server_file() {
		
		System.out.println(UUID.randomUUID().toString().replaceAll("-", "o"));
		
		RequestProcessorStaticFile p = new RequestProcessorStaticFile();
		p.setCacheSeconds(60);
		p.setRoot(IOUtil.getUserDirFile("docs").getPath());

		NettyWebServer s = server();
		s.addProcessor(p);
		s.start();
		ObjectUtil.waitFor(this, 60 * 1000);
		s.close();
	}

}
